/*
 * This file is part of the OdinMS Maple Story Server
 * Copyright (C) 2008 Patrick Huy <patrick.huy@frz.cc>
 *                    Matthias Butz <matze@odinms.de>
 *                    Jan Christian Meyer <vimes@odinms.de>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License version 3
 * as published by the Free Software Foundation. You may not use, modify
 * or distribute this program under any other version of the
 * GNU Affero General Public License.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

/** Borrowed from AzuraStory, thanks guys!
 *
 * @author DestinyFate
 *
 * Warrior 4th Job Advancement
 * 2081100.js
 */

importPackage(net.sf.odinms.client);

var status = 0;
var job;

function start() {
    status = -1;
    action(1, 0, 0);
}

function action(mode, type, selection) {
    if (mode == -1) {
        cm.dispose();
    } else {
        if (mode == 0 && status == 0) {
            cm.dispose();
            return;
        }
        if (mode == 1)
            status++;
        else
            status--;
        if (status == 0) {
            if (!(cm.getJob().equals(MapleJob.CRUSADER) ||
                cm.getJob().equals(MapleJob.WHITEKNIGHT) ||
                cm.getJob().equals(MapleJob.DRAGONKNIGHT) ||
                cm.getJob().equals(MapleJob.HERO) ||
                cm.getJob().equals(MapleJob.PALADIN) ||
                cm.getJob().equals(MapleJob.DARKKNIGHT))) {
                cm.sendOk("Why do you want to see me? There is nothing you want to ask me.");
                cm.dispose();
                return;
            } else if (cm.getJob().equals(MapleJob.HERO)) {
                cm.sendNext("You have become the best of warriors, my #bHero#k.You will gain the #bRush#k Skill which makes you attack mutiple enemies and give you indomitable will along with #bStance#k and #bAchilles#k.");
                //                cm.sendNext("This is not all about Hero. Hero is a well-balanced warrior who has excellent attack and defense power. It can learn various attack skills as well as combo attack if he trains himself.");
                //                cm.sendNext("Don't forget that it all depends on how much you train.");
                cm.dispose();
                return;
            } else if (cm.getJob().equals(MapleJob.PALADIN)) {
                cm.sendNext("You have become the best of warriors, my #bPaladint#k.You will gain the #bRush#k Skill which makes you attack mutiple enemies and give you indomitable will along with #bStance#k and #bAchilles#k.");
                //                cm.sendNext("This is not all about Paladin. Paladin is good at element-based attack and defense. It can use a new element-based and may break the limit of charge blow if you train yourself.");
                //                cm.sendNext("Don't forget that it all depends on how much you train.");
                return;
            } else if (cm.getJob().equals(MapleJob.DARKKNIGHT)){
                cm.sendNext("You have become the best of warriors, my #bDark Knight#k.\r\nYou will gain the #bRush#k Skill which makes you attack mutiple enemies and give you indomitable with along with #bStance#k and #bAchilles#k.");
                //                cm.sendNext("his is not all about Dark Knight. Dark Knight can use the power of darkness. It can attack with power of darkness which is unbelievably strong and may summon the figure of darkness.");
                //                cm.sendNext("Don't forget that it all depends on how much you train.");
                cm.dispose();
                return;
            }
            if (cm.getPlayer().getLevel() >= 120) {
                if (cm.getPlayer().getRemainingSp() <= (cm.getPlayer().getLevel() - 120) * 3 && cm.getJob().equals(MapleJob.CRUSADER)) {
                    cm.sendSimple("You're qualified to be a true warrior. \r\nDo you want job advancement?\r\n#b#L0# I want to advance to Hero.#l\r\n#b#L1#  Let me think for a while.#l");
                } else if (cm.getPlayer().getRemainingSp() <= (cm.getPlayer().getLevel() - 120) * 3 && cm.getJob().equals(MapleJob.WHITEKNIGHT)) {
                    cm.sendSimple("You're qualified to be a true warrior. \r\nDo you want job advancement?\r\n#b#L0# I want to advance to Paladin.#l\r\n#b#L1#  Let me think for a while.#l");
                } else if (cm.getPlayer().getRemainingSp() <= (cm.getPlayer().getLevel() - 120) * 3 && cm.getJob().equals(MapleJob.DRAGONKNIGHT)) {
                    cm.sendSimple("You're qualified to be a true warrior. \r\nDo you want job advancement?\r\n#b#L0# I want to advance to Dark Knight.#l\r\n#b#L1#  Let me think for a while.#l");
                } else {
                    cm.sendOk("Hmm...You have too many #bSP#k. You can't make the 4th job advancement with too many SP left.");
                    cm.dispose();
                    return;
                }
            } else {
                cm.sendOk("You're still weak to go to warrior extreme road. If you get stronger, come back to me.");
                return;
            }
        } else if (status == 1) {
            if (selection == 0 && cm.getJob().equals(MapleJob.CRUSADER)) {
                cm.changeJob(MapleJob.HERO);
                cm.getPlayer().gainAp(5);
                cm.gainItem(2280003,1);
                cm.teachSkill(1121001, 0, 10);
                cm.teachSkill(1120004, 0, 10);
                cm.teachSkill(1121008, 0, 10);
                cm.sendNext("You became the best warrior, the position of #bHero#k. Stronger power means more responsibility. Hope you get over all the tests you will have in future.");
                cm.dispose();
            } else if (selection == 0 && cm.getJob().equals(MapleJob.WHITEKNIGHT)) {
                cm.changeJob(MapleJob.PALADIN);
                cm.getPlayer().gainAp(5);
                cm.gainItem(2280003,1);
                cm.teachSkill(1220005, 0, 10);
                cm.teachSkill(1221001, 0, 10);
                cm.teachSkill(1221009, 0, 10);
                cm.sendNext("You became the best warrior, the position of #bPaladin#k. Stronger power means more responsibility. Hope you get over all the tests you will have in future.");
                cm.dispose();
            } else if (selection == 0 && cm.getJob().equals(MapleJob.DRAGONKNIGHT)) {
                cm.changeJob(MapleJob.DARKKNIGHT);
                cm.getPlayer().gainAp(5);
                cm.gainItem(2280003,1);
                cm.teachSkill(1320005, 0, 10);
                cm.teachSkill(1321001, 0, 10);
                cm.teachSkill(1321007, 0, 10);
                cm.sendNext("You became the best warrior, the position of #bDark Knight#k. Stronger power means more responsibility. Hope you get over all the tests you will have in future.");
                cm.dispose();
            } else {
                cm.sendOk("You don't have to hesitate to be the best Warrior..Whenever you make your decision, talk to me. If you're ready, I'll let you make the 4th job advancement.");
                cm.dispose();
            }
        }
    }
}